package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.entity.Course;
import com.example.demo.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;
    
    @GetMapping("/listAll")
    public Result<List<Course>> listAll() {
        return Result.success(courseService.findAll());
    }
    
    @GetMapping("/getById/{courseId}")
    public Result<Course> getById(@PathVariable Long courseId) {
        return Result.success(courseService.findById(courseId));
    }
    
    @PostMapping("/add")
    public Result<?> add(@RequestBody Course course) {
        return Result.success(courseService.save(course));
    }
} 